{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt text](https://github.com/callysto/callysto-sample-notebooks/blob/master/notebooks/images/Callysto_Notebook-Banner_Top_06.06.18.jpg?raw=true)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Mathematical Typesetting With Latex\n",
    "\n",
    "This will only serve as a brief introduction to mathematical typesetting with Latex, and will not cover many other aspects of the typesetting language. This tutorial will cover the basics of a few common mistakes and how to fix them, and provide you with a link to a cheat sheet. \n",
    "\n",
    "1. To put a variable in-line, surround it in dollar signs like so: `$x$`, which renders as $x$.\n",
    "1. To typeset an equation, surround it (on a new line) in double dollar signs: `$$equation$$`\n",
    "1. You can also use this syntax:\n",
    "```latex\n",
    "\\begin{equation}\n",
    "       your_equation_here\n",
    "\\end{equation}\n",
    "  ```\n",
    "1. Special symbols start with a backslash (`\\`). For example, the greek letter $\\alpha$ is typed as `$\\alpha$`. \n",
    "\n",
    "1. Fractions can be typeset with `\\frac{numerator}{denominator}`\n",
    "1. Square roots are `\\sqrt{stuff inside square root}`\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you want special symbols in line, simply call it by its name, such as $\\alpha$, $\\gamma$, $\\epsilon$, $\\Delta$, $\\nabla$ and so on are called by typing `$\\alpha$`, `$\\gamma$`, `$\\epsilon$`, `$\\Delta$`, and `$\\nabla$` etc. [This link leads](http://tug.ctan.org/info/symbols/comprehensive/symbols-a4.pdf) to a comprehensive symbol list and their Latex commands. Of course, sometimes a Google search is faster. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Latex Basics\n",
    "\n",
    "#### Double Click Me\n",
    "You can start equations easily:\n",
    "$$ c  = \\sqrt{a^2 + b^2}$$\n",
    "notice how in the above, the variables appearing under the square root are surrounded by curly brackets (`{ }`), and powers are done with carrots (`^`)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Double Click Me\n",
    "\n",
    "You can also type equations using this syntax:\n",
    "\\begin{equation}\n",
    "a = \\frac{x^3 +\\Gamma}{\\int e^{-x^2} dx}\n",
    "\\end{equation}\n",
    "\n",
    "Notice here how the numerator of the fraction appears in curly braces, and the denominator appears in separate curly braces. Note that capital Greek letters are found by capitalizing the first letter in your Latex command. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Double Click Me\n",
    "\n",
    "Also notice the exponent, this time we included curly brackets. This is because without them only the first character will become a superscript, as demonstrated below. \n",
    "\n",
    "\\begin{equation}\n",
    "a = x^-10\n",
    "\\end{equation}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Double Click Me\n",
    "\n",
    "The above doesn't render as you would expect. However, we can fix this by adding curly braces around the exponent as follows\n",
    "\\begin{equation}\n",
    "a = x^{-10}\n",
    "\\end{equation}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Double Click Me\n",
    "\n",
    "You can also include vectors on variables\n",
    "\\begin{equation}\n",
    "\\vec{F} = m \\vec{a}\n",
    "\\end{equation}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Double Click Me\n",
    "\n",
    "The asterisk symbol may not render how you hope for multiplication in Latex, and it is often better to use `\\times`. For example, compare\n",
    "\n",
    "\\begin{equation}\n",
    "a * b = ab\n",
    "\\end{equation}\n",
    "\n",
    "versus\n",
    "\n",
    "\\begin{equation}\n",
    "a \\times b = ab\n",
    "\\end{equation}\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Double Click Me\n",
    "\n",
    "If you need to put parenthesis around a fraction, sometimes your equation may not render nicely, for example\n",
    "\n",
    "\\begin{equation}\n",
    "f(x) = a \\times ( \\frac{ x^2 }{ \\sqrt{ x^2 + \\tan(x) } } )\n",
    "\\end{equation}\n",
    "\n",
    "In order to make your parenthesis larger, you need to include the `\\left` and `\\right` commands besides your parenthesis as follows\n",
    "\n",
    "\\begin{equation}\n",
    "f(x) = a \\times \\left( \\frac{ x^2 }{ \\sqrt{ x^2 + \\tan(x) } } \\right)\n",
    "\\end{equation}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Latex Common Errors\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Long subscripts need to be wrapped in curly braces to render correctly"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Double Click Me\n",
    "\n",
    "Notice how the equation \n",
    "\\begin{equation}\n",
    "a = x_10\n",
    "\\end{equation}\n",
    "\n",
    "Doesn't render how you want it to, but \n",
    "\\begin{equation}\n",
    "a = x_{10}\n",
    "\\end{equation}\n",
    "does once you include the curly braces.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Spaces in equations are ignored"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Double Click Me\n",
    "Notice what happens to words included in the math environment\n",
    "$$\n",
    "If you use words as a variable, they become hard to read = x_a^2\n",
    "$$\n",
    "\n",
    "If you need to include words in your equations, you can do so with `\\text{}`\n",
    "$$\n",
    "\\text{Now we can read this easily once we've rendered the math} = x_a^2\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### You cannot include percent signs without a little extra work"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Double Click Me\n",
    "\n",
    "If you want to include a percent sign in a mathematical equation, you need to escape it with `\\` as a percent sign denotes a comment in Latex\n",
    "\n",
    "$$\n",
    "100 % That's because a percent sign is a comment in latex!\n",
    "$$\n",
    "To escape the comment, simply add a backslash\n",
    "$$ 100 \\% $$\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Missing a Curly Bracket\n",
    "\n",
    "If you're missing a curly bracket when using a Latex command, say in a fraction, your equation won't render as shown in a simple example below\n",
    "\n",
    "\\begin{equation}\n",
    "x = \\frac{ a } { y\n",
    "\\end{equation}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To fix this, simply add the missing parenthesis \n",
    "\n",
    "\\begin{equation}\n",
    "x = \\frac{ a } { y } \n",
    "\\end{equation}\n",
    "\n",
    "Note however that anytime you have an error in your Latex it will simply not render as shown above, and sometimes its a bit of work finding the offending parenthesis."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Latex is very extensive for mathematical typesetting, and we can't cover it all here. However, it's fairly intuitive and with a little practice significantly faster than using the equation editors in other tools. Feel free to try creating your own equations now. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "### Exercises\n",
    "1. Fix the following to correctly represent the formula for calculating the surface area of a sphere\n",
    "\n",
    "$$\n",
    "Area = 4 pi r2\n",
    "$$  \n",
    "  \n",
    "2. Fix the following to correctly represent the formula for calculating the volume of a sphere\n",
    "\\begin{equation}\n",
    "Volume = \\frac{4} / {3} pi r3\n",
    "\\end{equation}\n",
    "3. Make sure pi is showing up as a symbol in questions 1 & 2.\n",
    "4. In this sentence, change the variables x, Y, and y to ensure they render as LateX variables.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt text](https://github.com/callysto/callysto-sample-notebooks/blob/master/notebooks/images/Callysto_Notebook-Banners_Bottom_06.06.18.jpg?raw=true)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
